package com.ls.x.activity;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;

public class CameraActivity extends Activity {
	/** Called when the activity is first created. */
	private String logTag = "Exception";
	private String image_dir_path;
	private String image_filename;
	private String imageFile;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			Intent intent = getIntent();
			image_dir_path = intent.getExtras().getString("image_dir_path");
			image_filename = intent.getExtras().getString("image_filename");
			intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			File dir = new File(image_dir_path);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			imageFile = image_dir_path + image_filename;
			Log.d("lijing", "拍照保存路径：" + imageFile);
			File out = new File(imageFile);
			Uri uri = Uri.fromFile(out);
			intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
			startActivityForResult(intent, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		try {
			if (requestCode != 0) {
				return;
			}
			if (resultCode == -1) {
				Intent intent = getIntent();
				intent.putExtra("backcode", 1);
				CameraActivity.this.setResult(0, intent);
				finish();
				return;
			}
		} catch (Exception e) {
			// TODO: handle exception
			Log.d(logTag, e.getMessage());
		}
	}
}
